﻿--[[
	Widget name	  	MenuStrip
	Author     	 	Kurapica
--]]
     
-- MenuStrip
do
	IGAS:NewAddon("IGAS_Studio")
	
    ------------------------------------------------------
	---------------------   MenuStrip   -------------------
	------------------------------------------------------
	local _WidgetName = "MenuStrip"
    local _Base = "Frame"

    -- Scripts
	local _FrameBackdrop = {
        bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        tile = true, tileSize = 16, edgeSize = 16,
        insets = { left = 3, right = 3, top = 3, bottom = 3 }
	}
	
	local function Menu_OnClick(self)
		self.MenuList.Visible = not self.MenuList.Visible
	end
	
	-- ScriptType
	local _ScriptType = {
	}
	    
	-- Function
	local _Function = {
		-- Dispose
		-- No need, only need to be created, so ignore.
		
		-- AddMenuItem
		["AddMenuItem"] = function(self, ...)
			local name
			local list
			local menu
			
			if select("#", ...) == 0 then
				return
			end
			
			-- Create Menu
			name = select(1, ...)
			if name and type(name) == "string" and name ~= "" then
				local i = 1
				while self:GetChild("Menu"..i) and self:GetChild("Menu"..i).Text ~= name do
					i = i + 1
				end
				if self:GetChild("Menu"..i) then
					list = self:GetChild("Menu"..i).MenuList
				else
					menu = CreateFrame("Button", "Menu"..i, self)
					menu:SetNormalFontObject(GameFontNormal)
					menu:SetDisabledFontObject(GameFontDisable)
					menu:SetHighlightFontObject(GameFontHighlight)
					menu.Text = name
					menu.Height = 24
					menu.Width = menu:GetTextWidth() + 10
					menu:SetPoint("TOP", self, "TOP", 0, -10)
					menu:SetPoint("BOTTOM", self, "BOTTOM", 0, 10)
					if i == 1 then
						menu:SetPoint("LEFT", self, "LEFT", 10, 0)
					else
						menu:SetPoint("LEFT", self:GetChild("Menu"..(i-1)), "RIGHT", 10, 0)
					end
					menu:RegisterForClicks("AnyUp")
					
					list = CreateFrame("DropDownList", "MenuList", menu)
					list.ShowOnCursor = false
					list:SetPoint("TOPLEFT", menu, "BOTTOMLEFT")
					
					menu.OnClick = Menu_OnClick
				end
			else
				return
			end
			
			for i = 2, select("#", ...)-1 do
				name = select(i, ...)
				if name and type(name) == "string" and name ~= "" then
					menu = list:AddMenuButton(name)
					list = CreateFrame("DropDownList", "MenuList", menu)
					list.ShowOnCursor = false
					menu:SetDropDownList(list)
				else
					return
				end
			end
			
			if select("#", ...) > 1 then
				name = select(select("#", ...), ...)
				if name and type(name) == "string" and name ~= "" then
					return list:AddMenuButton(name)
				end
			else
				return
			end
		end,
    }
    
	-- Property
	local _Property = {
    }
    
    -- New    
    local function _New(name, parent)	
		local frame = CreateFrame("Frame",name,parent)	        
				
		frame:SetBackdrop(_FrameBackdrop)
		frame:SetBackdropColor(0,0,0,1)
		frame:SetPoint("TOPLEFT", parent, "TOPLEFT")
		frame:SetPoint("TOPRIGHT", parent, "TOPRIGHT")
		frame.Height = 30
		
        return frame
    end
	
    local _WidgetInfo = {
        ["WidgetName"] = _WidgetName,
        ["Base"] = _Base,
        ["Function"] = _Function,
        ["Property"] = _Property,
        ["ScriptType"] = _ScriptType,
        ["New"] = _New,
		-- Special Item
    }
    
    Widget.MenuStrip = IGAS:NewWidget(_WidgetInfo)
end